package com.example.fp.cgc.util

import org.springframework.beans.BeansException
import org.springframework.context.ApplicationContext
import org.springframework.context.ApplicationContextAware
import org.springframework.stereotype.Component

@Component
object SpringUtil :ApplicationContextAware {


    private var applicationContext: ApplicationContext? = null


    @Throws(BeansException::class)
    override fun setApplicationContext(applicationContext: ApplicationContext) {
        SpringUtil.applicationContext = applicationContext
    }

    fun getBean(beanname: String): Any {
        return applicationContext!!.getBean(beanname)
    }

    fun <T> getBean(tClass: Class<T>): T {
        return applicationContext!!.getBean(tClass)
    }

}